const App = {
  data() {
    return {
      cun: [],
      party_organization_activities: {},
      pageTitle: "",
      Recorder: [],
      Manager: [],
      activityType: [
        {
          value: "党员大会",
          label: "党员大会",
        },
        {
          value: "党委会",
          label: "党委会",
        },
        {
          value: "党小组会",
          label: "党小组会",
        },
        {
          value: "党课",
          label: "党课",
        },
        {
          value: "双联系双报道",
          label: "双联系双报道",
        },
        {
          value: "主题党日",
          label: "主题党日",
        },
      ],

      activityDevelop: [
        {
          value: "线上开展",
          label: "线上开展",
        },
        {
          value: "线下开展",
          label: "线下开展",
        },
      ],
      value: [], // 初始化 labelNumber 属性
      hjoptions: [], //省市区县
      Nation: [], //民族
      fileList: [], //身份证照片
    };
  },

  mounted() {
    let TABLE_NAME = sessionStorage.getItem("TABLE_NAME");
    console.log(TABLE_NAME);
    this.Data = TABLE_NAME;
    this.Add();
    this.dang();
  },
  methods: {
    dang() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
        method: "post",
        data: {
          Data: "party_organization", //表名
          Condition: 'Row_Status="0"',
        },
        success: (res) => {
          console.log("res", res);
          _this.Manager = res;
        },
        error: (err) => {
          console.log(err);
        },
        complete: (XMLHttpRequest) => {
          requestPretreatment(XMLHttpRequest);
      },
      });
    },
    beforeUpload(file) {
      console.log(file);

      // 这里可以添加对文件类型和大小的校验
      const isAllowedType = [
        "image/jpeg",
        "image/png",
        "application/pdf",
        "text/plain",
      ].includes(file.type);
      if (!isAllowedType) {
        this.$message.error("不支持的文件类型！");
      }
      return isAllowedType;
    },
    Add() {
      console.log();

      const Party_Organization_Activity_SerialNumber = sessionStorage.getItem(
        "Party_Organization_Activity_SerialNumber"
      );
      console.log(Party_Organization_Activity_SerialNumber);

      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
        method: "post",
        data: {
          Data: "party_organization_activities", //表名
          Condition:
            "Party_Organization_Activity_SerialNumber='" +
            Party_Organization_Activity_SerialNumber +
            "'",
        },
        success: (res) => {
          console.log("res", res);

          _this.party_organization_activities = res[0];
          _this.cun = res;
        },
        complete: (XMLHttpRequest) => {
          requestPretreatment(XMLHttpRequest);
      },
        error: (err) => {
          console.log(err);
        },
      });
      //查personal_information表的lD_Card_Number
      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
        method: "post",
        data: {
          Data: "personal_information", //表名
          Condition: "Row_Status='0'",
        },
        success: (res) => {
          console.log("res", res);
          _this.Recorder = res;
          console.log(_this.Recorder);
        },
        complete: (XMLHttpRequest) => {
          requestPretreatment(XMLHttpRequest);
      },
        error: (err) => {
          console.log(err);
        },
      });
    },

    //提交表单
    handleSubmit() {
      this.cun[0].Recorder_SerialNumber =
        this.party_organization_activities.Recorder_SerialNumber;
      console.log(this.cun);
      let lJSONObject = new Object();
      lJSONObject.party_organization_activities = this.cun; //换表

      const Party_Organization_Activity_SerialNumber = sessionStorage.getItem(
        "Party_Organization_Activity_SerialNumber"
      );
      console.log(Party_Organization_Activity_SerialNumber);
      this.fileList.forEach((file) => {
        file.Party_Organization_Activity_SerialNumber =
          Party_Organization_Activity_SerialNumber;
        file.Activity_Summary_URL = file.url;
        console.log(file);
      });

      console.log(this.fileList);
      let lJSONObject_party_organization_activities_summary = new Object();
      lJSONObject_party_organization_activities_summary.party_organization_activities_summary =
        this.fileList; //换表
      let lJSONObject_DataSet = new Object(); // Modify
      lJSONObject_DataSet.Add =
        lJSONObject_party_organization_activities_summary; //换表
      lJSONObject_DataSet.Modify = lJSONObject; //换表
      console.log(lJSONObject_DataSet);
      this.AddApi(lJSONObject_DataSet);
    },
    AddApi(lJSONObject_DataSet) {
      console.log(lJSONObject_DataSet);
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/clientOperation/generalSaveForClient`,
        method: "post",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: (res) => {
          console.log(res);
          // 在普通 JavaScript 中使用 MessageBox
          ElMessage({
            message: "提交成功",
            type: "success",
            plain: true,
            duration: 1000, // 消息显示时长（毫秒）
          });
          // 等待 3 秒后回退页面
          setTimeout(() => {
            window.history.back();
          }, 1000);
        },
        complete: (XMLHttpRequest) => {
          requestPretreatment(XMLHttpRequest);
      },
        error: (err) => {
          console.log(err);
        },
      });
    },
    beforeRemove(file, fileList) {
      console.log("beforeRemove", file, fileList);
      // 过滤掉当前要删除的文件
      const newFileList = fileList.filter((item) => item.uid !== file.uid);
      // 更新文件列表（具体实现取决于你的框架或组件）
      this.fileList = newFileList; // Vue/React 等框架中更新状态的方式
      // 返回 true 允许删除，返回 false 阻止删除
      return true;
    },
    beforeUpload(file) {
      console.log(file);

      let result = uploadBinaryFile(file);
      result
        .then((res) => {
          console.log(res);

          console.log(res.fileName);
          console.log(photo);
          this.fileList.push({
            name: file.name,
            url: `${photo}${res.fileName}`,
            uid: file.uid,
          });
        })
        .catch((error) => {
          console.error("上传失败:", error);
        });
    },
    goBack() {
      window.history.back();
    },
  },
};
const { createApp, ref } = Vue;
const app = createApp(App);
app.use(ElementPlus,{locale: zhCn});
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
const ElMessageBox = ElementPlus.ElMessageBox;
app.mount("#app");
